#!/usr/bin/env python

# Copyright 2020 Stanford University, Los Alamos National Laboratory
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# IMPORTANT:
#   * legion_cffi.py.in is used as an input to string.format()
#   * legion_cffi.py is a generated file and should not be modified by hand

from __future__ import absolute_import, division, print_function, unicode_literals

import cffi, os

from flexflow.config import flexflow_python_interpreter

header = {header}
libname = {libname}

ffi = cffi.FFI()
ffi.cdef(header)
if flexflow_python_interpreter() == 'native':
  if 'PYTHONPATH' in os.environ:
    python_paths = os.environ['PYTHONPATH'].split(':')
    flexflow_lib = '/flexflow/core/' + libname
    for p in python_paths:
      flexflow_lib_p = p + flexflow_lib
      if os.path.exists(flexflow_lib_p):
        flexflow_lib = flexflow_lib_p
        break
  else:
    flexflow_lib = 'flexflow/core/' + libname
else:
  flexflow_lib = None
ffc = ffi.dlopen(flexflow_lib)
